package com.beiding.v2.test.pg;

import java.util.Collection;
import java.util.Iterator;

public class ContentUtils {

    public interface Handler<T> {
        String handle(T t);
    }

    public static <T> String join(Collection<T> ts, Handler<T> handler, String split) {
        Iterator<T> iterator = ts.iterator();
        if (iterator.hasNext()) {
            StringBuilder builder = new StringBuilder();
            builder.append(handler.handle(iterator.next()));
            while (iterator.hasNext()) {
                builder.append(split).append(handler.handle(iterator.next()));
            }
            return builder.toString();
        } else {
            return "";
        }
    }

}
